package object

import "ldaccount/internal/model"

// AccImport 导入参数
type AccImport struct {
	GID         string `json:"g_id" validate:"required"`
	Mobile      string `json:"mobile" validate:"required"`
	Email       string `json:"email"`
	Password    string `json:"password"`
	UserName    string `json:"user_name"`
	CountryCode string `json:"country_code"`
	Origin      string `json:"origin"`
	Created     int64  `json:"created" validate:"required"`
}

// AccInfo acc 输出
type AccInfo struct {
	GID      string `json:"g_id"`
	Mobile   string `json:"mobile"`
	Email    string `json:"email"`
	UserName string `json:"user_name"`
	Modified int64  `json:"modified"`
	Status   string `json:"status"`
	Avatar   string `json:"avatar"`
	Token    string `json:"token,omitempty"`
}

// PlatformUserInfo 平台用户信息
type PlatformUserInfo struct {
	AppId    string `json:"app_id"`
	OpenId   string `json:"open_id"`
	UnionId  string `json:"union_id"`
	Nickname string `json:"nickname"`
	Avatar   string `json:"avatar"`
	Platform string `json:"platform"`
}

// GetInnerPlatform 获取内部平台编码
func (p *PlatformUserInfo) GetInnerPlatform() int8 {
	switch p.Platform {
	case model.ChannelWechatMpStr:
		return model.ChannelWechatMp
	case model.ChannelWechatMinaStr:
		return model.ChannelWechatMina
	case model.ChannelWecomSuiteStr:
		return model.ChannelWecomSuite
	default:
		return 0
	}
}

// LoginAccInfo 登陆返回用户信息
type LoginAccInfo struct {
	GID      string `json:"gid"`
	Mobile   string `json:"mobile"`
	Email    string `json:"email"`
	UserName string `json:"user_name"`
	Status   string `json:"status"`
	AppId    string `json:"app_id"`
	Platform string `json:"platform"`
	OpenId   string `json:"open_id"`
	Avatar   string `json:"avatar"`
}

// NeedScan 未扫码
func (l *LoginAccInfo) NeedScan() {
	l.Status = "needScan"
}

// NeedRegister 需要注册
func (l *LoginAccInfo) NeedRegister() {
	l.Status = "needRegister"
}

// OK 正常登陆
func (l *LoginAccInfo) OK() {
	l.Status = "ok"
}

// SetPlatform 设置外部平台编码
func (l *LoginAccInfo) SetPlatform(p int8) {
	switch p {
	case model.ChannelWechatMp:
		l.Platform = model.ChannelWechatMpStr
	case model.ChannelWechatMina:
		l.Platform = model.ChannelWechatMinaStr
	case model.ChannelWecomSuite:
		l.Platform = model.ChannelWecomSuiteStr
	default:
		l.Platform = ""
	}
}

// NewLoginAccInfo 新建
func NewLoginAccInfo(gID, mobile, email, userName, appId, openId, avatar string, platform int8) *LoginAccInfo {
	ret := &LoginAccInfo{
		GID:      gID,
		Mobile:   mobile,
		Email:    email,
		UserName: userName,
		AppId:    appId,
		OpenId:   openId,
		Avatar:   avatar,
	}
	ret.SetPlatform(platform)
	return ret
}

// WechatMpQrcode 微信公众号 QRcode
type WechatMpQrcode struct {
	// 获取的二维码ticket，凭借此ticket可以在有效时间内换取二维码
	Ticket string `json:"ticket"`
	// 该二维码有效时间，以秒为单位。 最大不超过2592000（即30天）
	ExpireSeconds int64 `json:"expire_seconds"`
	// 二维码图片解析后的地址
	Url string `json:"url"`
}
